﻿using System;
using System.Collections.Generic;
using BuzzX8.Xmpp.StreamElements.Security;

namespace BuzzX8.Xmpp.StreamElements.Builders
{
    public class TlsElementBuilder : StreamElementBuilder<TlsElement>
    {
        protected override IEnumerable<string> GetSupportedElementNames()
        {
            return new [] {"starttls", "proceed", "failure"};
        }

        protected override void AddAttributeToRootElement(string name, string value)
        {
            if (name == "xmlns" && value != XmppNamespaces.Tls) throw new ArgumentException();
        }

        protected override void AddAttributeToCurrentNode(string name, string value)
        { }

        protected override TlsElement CreateNewElement(string name)
        {
            switch (name)
            {
                case "starttls":
                    return TlsElement.StartTls;

                case "proceed":
                    return TlsElement.Proceed;

                case "failure":
                    return TlsElement.Failure;

                default:
                    throw new NotImplementedException();
            }
        }
    }
}
